package com.hefeng.controller;


import com.hefeng.domain.WxUser;
import com.hefeng.mapper.WxUserMapper;
import com.hefeng.service.IWxUserService;
import com.hefeng.service.impl.WxUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hefeng.common.log.annotation.Log;
import com.hefeng.common.log.enums.BusinessType;
import com.hefeng.common.security.annotation.RequiresPermissions;
import com.hefeng.common.core.web.controller.BaseController;
import com.hefeng.common.core.web.domain.AjaxResult;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 微信用户Controller
 *
 * @author ruoyi
 * @date 2022-09-02
 */
@RestController
@RequestMapping("/user/")
public class WxUserController extends BaseController {
    @Autowired
    private IWxUserService wxUserService;

    /**
     * 查询微信用户列表
     */
    @RequiresPermissions("system:user:list")
    @RequestMapping("/list/{currPage}/{pageSize}")
    public List<WxUser> findPage(@RequestParam(required = false) Integer pageNum, @RequestParam(required = false) Integer pageSize){

        List<WxUser> list=wxUserService.selectWxUserList(pageNum, pageSize);
        return list;
    }


    /**
     * 获取微信用户详细信息
     */
    @RequiresPermissions("system:user:query")
    @PostMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Integer userId) {
        return AjaxResult.success(wxUserService.selectWxUserByUserId(userId));
    }

    /**
     * 新增微信用户
     */
    @RequiresPermissions("system:user:add")
    @Log(title = "微信用户", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody WxUser wxUser) {
        return toAjax(wxUserService.insertWxUser(wxUser));
    }

    /**
     * 修改微信用户
     */
    @RequiresPermissions("system:user:edit")
    @Log(title = "微信用户", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody WxUser wxUser) {
        return toAjax(wxUserService.updateWxUser(wxUser));
    }

    /**
     * 删除微信用户
     */
    @RequiresPermissions("system:user:remove")
    @Log(title = "微信用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Integer[] userIds) {
        return toAjax(wxUserService.deleteWxUserByUserIds(userIds));
    }

}
